package team2.arsystem.GUI;

import team2.arsystem.Controller.ApplicationController;
import team2.arsystem.Utilities.CommandConstants;
import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class AddMembers extends Activity{

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.addnewmemberscreen);
		
		final EditText firstNameEditText = (EditText)findViewById(R.id.editTextFirstName);
        final EditText middleNameEditText = (EditText)findViewById(R.id.editTextMiddleName);
        final EditText lastNameEditText = (EditText)findViewById(R.id.editTextLastName);
        final EditText mobileNumberEditText = (EditText)findViewById(R.id.editTextMobileNumber);
        Button okButton = (Button)findViewById(R.id.buttonOKAddMember);
        Button cancelButton = (Button)findViewById(R.id.buttonCancelAddMember);
        
        /* If OK button is clicked*/
        okButton.setOnClickListener(new OnClickListener() {
			
        	public void onClick(View v) {
        		
        	String[] memberDetails = new String[4];	
        	memberDetails[0] = firstNameEditText.getText().toString();
        	memberDetails[1] = middleNameEditText.getText().toString();
        	memberDetails[2] = lastNameEditText.getText().toString();
        	memberDetails[3] = mobileNumberEditText.getText().toString();
        	
        	if((ApplicationController.getApplicationController().passCommand(CommandConstants.addNewMember,memberDetails)))
        	{
        		/*Member was added successfully*/
        		try
        		{
        			Dialog dialogOK = new Dialog(AddMembers.this);
        			dialogOK.setContentView(R.layout.popupbox);
        			dialogOK.setTitle("Account Reminder System");
        			
        		        			
        			TextView dialogText = (TextView)dialogOK.findViewById(R.id.textViewDialogMessage);
        			dialogText.setText("The member was successfully added");
        			
        			
                    Button button = (Button) dialogOK.findViewById(R.id.buttonDialogOK);
                   
                    button.setOnClickListener(new OnClickListener() {
                   
                        public void onClick(View v) {
                        	
                        	try
                        	{
                        	 Class menuScreen = Class.forName("team2.arsystem.GUI."+"MembersMenuScreen");
                    		 Intent myIntent = new Intent(AddMembers.this,menuScreen);
                    		 startActivity(myIntent);
                        	}
                        	catch(Exception e){
                    			 e.printStackTrace();
                    		 }
                    		 
                        }
                    });
        		    
            		 
                    dialogOK.show();
        		}
        		catch(Exception e)
        		{
        			 e.printStackTrace();
        		}
        	}
        		
			}
		});
        
         /* If Cancel button is clicked*/
        cancelButton.setOnClickListener(new OnClickListener() {
			
        	public void onClick(View v) {
        		
        	  	try
                {
                   	 Class menuScreen = Class.forName("team2.arsystem.GUI."+"MembersMenuScreen");
                	 Intent myIntent = new Intent(AddMembers.this,menuScreen);
                	 startActivity(myIntent);
                }
                catch(Exception e)
               	{
               		 e.printStackTrace();
                }
                    		 
            }
        	
        });
        		    
            		 
	
        
        	
	}
	

}
